<!DOCTYPE html>
<html xmlns:layout="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
	layout:decorate="~{common/layoutAdmin}">

<head>
	<meta charset="UTF-8">
	<title>今日建议</title>
</head>

<body>
	<div layout:fragment="fragment_body">
		<el-row :gutter="20">
			<el-col :span="24">
				<el-button type="primary" @click="openSuggestInfo(null)">添 加</el-button>
				<el-table :data="suggestInfos" border highlight-current-row style="width: 100%">
					<!-- -->
					<el-table-column prop="suggestText" label="建议内容"></el-table-column>
					<el-table-column prop="suggestShow" label="显示">
						<template slot-scope="scope">
							{{scope.row.suggestShow === 1?'是':'隐藏'}}
						</template>
					</el-table-column>
					<el-table-column prop="suggestTime" label="时间"></el-table-column>
					<el-table-column label="操作" width="160px">
						<template slot-scope="scope">
							<el-button @click="openSuggestInfo(scope.row)" type="text" size="small">修 改</el-button>
							<el-popconfirm title="是否删除？" @confirm="delSuggestInfo(scope.row.suggestId)">
								<el-button slot="reference" type="text" size="small">删 除</el-button>
							</el-popconfirm>
						</template>
					</el-table-column>
				</el-table>
			</el-col>
		</el-row>
		<!--弹框-->
		<el-dialog :title="suggestInfoForm.ttitle" :visible.sync="suggestInfoForm.visible" width="30%">
			<el-form :model="suggestInfoForm" :rules="suggestInfoRules" ref="suggestInfoForm" label-width="100px">
				<!-- -->
				<el-form-item label="建议内容" prop="suggestText">
					<el-input type="textarea" :rows="5" autosize v-model="suggestInfoForm.suggestText"></el-input>
				</el-form-item>
				<el-form-item label="显示" prop="suggestShow">
					<el-select v-model="suggestInfoForm.suggestShow" placeholder="请选择">
				    <el-option
				      v-for="item in [{value:'0',label:'不显示'}, {value:'1',label:'显示'}]"
				      :key="item.value"
				      :label="item.label"
				      :value="item.value">
				    </el-option>
				  </el-select>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="closeSuggestInfo">取 消</el-button>
				<el-button type="primary" @click="saveSuggestInfo">保 存</el-button>
			</span>
		</el-dialog>
	</div>
</body>
<script type="text/javascript" layout:fragment="fragment_script">
	let vueData = {
		suggestInfos: [],
		selectSuggestInfo: null,
		suggestInfoForm: {
			visible: false,
			ttitle: '新增/修改',
			suggestId : '',
			suggestText : '',
			suggestShow : '1',
			suggestTime : '',
		},
		suggestInfoQuery: {
			page: '',
			size: '',
		},
		suggestInfoRules: {
			suggestText: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			suggestShow: [
				{required: true, message: '不能为空', trigger: 'blur'}
			]
		},
	}
	let vueMethods = {
		getSuggestInfos() {
			let that = this
			postRequst('/getSuggests', that.suggestInfoQuery, true).then(function (resp) {
				that.suggestInfos = resp.rows
				if (resp.rows && resp.rows.length > 0) {
					that.selectSuggestInfo = resp.rows[0]
				}
			})
		},
		openSuggestInfo(row) {
			let that = this
			if (row) {
				that.suggestInfoForm.ttitle = '修改'
				that.suggestInfoForm.suggestId = row.suggestId
				that.suggestInfoForm.suggestText = row.suggestText
				that.suggestInfoForm.suggestShow = row.suggestShow + ''
			} else {
				that.suggestInfoForm.ttitle = '新增'
				that.suggestInfoForm.suggestId = ''
				that.suggestInfoForm.suggestText = ''
				that.suggestInfoForm.suggestShow = '1'
			}
			that.suggestInfoForm.visible = true
		},
		closeSuggestInfo() {
			this.$refs["suggestInfoForm"].resetFields();
			this.suggestInfoForm.visible = false
		},
		saveSuggestInfo() {
			let that = this
			this.$refs["suggestInfoForm"].validate((valid) => {
				if (valid) {
					postRequst('/saveSuggest', that.suggestInfoForm).then(function (resp) {
						if (resp.status == 0) {
							that.getSuggestInfos()
							that.suggestInfoForm.visible = false
							that.$message({message: resp.msg, type: "success"});
						} else {
							that.$message({message: resp.msg, type: "error"});
						}
					})
				}
			});
		},
		delSuggestInfo(suggestId) {
			let that = this
			postRequst('/delSuggest', {suggestId: suggestId}, true).then(function (resp) {
				if (resp.status == 0) {
					that.getSuggestInfos()
					that.$message({message: resp.msg, type: "success"});
				} else {
					that.$message({message: resp.msg, type: "error"});
				}
			})
		},
	}
	function vueCreated() {
		let that = this
		that.getSuggestInfos()
	}
</script>

</html>